package org.example.task.constant.response;


import java.util.HashMap;
import java.util.Map;

/**
 * 状态码对应默认消息映射
 */
public class StatusMessage {
    private static final Map<Integer, String> DEFAULT_MESSAGES = new HashMap<>();

    static {
        // 2xx
        DEFAULT_MESSAGES.put(HttpStatus.SUCCESS, "操作成功");
        DEFAULT_MESSAGES.put(HttpStatus.CREATED, "资源创建成功");

        // 4xx
        DEFAULT_MESSAGES.put(HttpStatus.BAD_REQUEST, "请求参数错误");
        DEFAULT_MESSAGES.put(HttpStatus.UNAUTHORIZED, "身份验证失败");

        // 5xx
        DEFAULT_MESSAGES.put(HttpStatus.INTERNAL_ERROR, "系统繁忙，请稍后重试");
    }

    /**
     * 获取状态码对应的默认消息
     * @param code 状态码
     * @return 如果没有匹配则返回空字符串
     */
    public static String getMessage(int code) {
        return DEFAULT_MESSAGES.getOrDefault(code, "");
    }
}